package com.yunyi.common.core.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yunyi.common.annotation.Excel;
import com.yunyi.common.core.domain.BaseEntity;
import com.yunyi.common.xss.Xss;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 用户表
 * @TableName sys_user
 */
@TableName(value ="sys_user")
public class SysUser extends BaseEntity {
    /**
     * 编号
     */
    @TableId(value = "id", type = IdType.AUTO)
    @Excel(name = "用户序号", cellType = Excel.ColumnType.NUMERIC, prompt = "用户编号")
    private Integer id;

    /**
     * 归属公司
     */
    @TableField(value = "company_id")
    @Excel(name = "归属公司", type = Excel.Type.IMPORT)
    private String company_id;

    /**
     * 归属部门
     */
    @TableField(value = "office_id")
    @Excel(name = "归属部门", type = Excel.Type.IMPORT)
    private String office_id;

    /**
     * 登录名
     */
    @TableField(value = "login_name")
    @Excel(name = "登录名")
    private String login_name;

    /**
     * 密码
     */
    @TableField(value = "password")
    @Excel(name = "密码")
    private String password;

    /**
     * 账号使用人，医生id或者管理员id
     */
    @TableField(value = "use_by")
    @Excel(name = "使用人")
    private String use_by;

    /**
     * 工号
     */
    @TableField(value = "no")
    @Excel(name = "工号")
    private String no;

    /**
     * 姓名
     */
    @TableField(value = "name")
    @Excel(name = "真实姓名")
    private String name;

    /**
     * 邮箱
     */
    @TableField(value = "email")
    @Excel(name = "邮箱")
    private String email;

    /**
     * 电话
     */
    @TableField(value = "phone")
    @Excel(name = "座机")
    private String phone;

    /**
     * 手机
     */
    @TableField(value = "mobile")
    @Excel(name = "手机号")
    private String mobile;

    /**
     * 职位
     */
    @TableField(value = "job_name")
    @Excel(name = "职位")
    private String job_name;

    /**
     * 职级
     */
    @TableField(value = "job_level")
    @Excel(name = "职级")
    private String job_level;

    /**
     * 用户类型
     */
    @TableField(value = "user_type")
    @Excel(name = "用户类型", readConverterExp = "0=管理员,1=分配员,2=医院,3=医生")
    private String user_type;

    /**
     * 用户头像
     */
    @TableField(value = "photo")
    @Excel(name = "用户头像")
    private String photo;

    /**
     * 最后登陆IP
     */
    @TableField(value = "login_ip")
    @Excel(name = "最后登录IP", type = Excel.Type.EXPORT)
    private String login_ip;

    /**
     * 最后登陆时间
     */
    @TableField(value = "login_date")
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Excel.Type.EXPORT)
    private Date login_date;

    /**
     * 是否可登录
     */
    @TableField(value = "login_flag")
    @Excel(name = "是否可登录", readConverterExp = "0=可登录,1=不可登录")
    private String login_flag;

    /**
     * token
     */
    @TableField(value = "token")
    private String token;

    /**
     * 删除标记
     */
    @TableField(value = "del_flag")
    @Excel(name = "删除标记", readConverterExp = "0=未删除,1=已删除")
    private String del_flag;

    /**
     * 企业帐套
     */
    @TableField(value = "account_id")
    @Excel(name = "企业套账")
    private String account_id;

    /**
     * 
     */
    @TableField(value = "qrcode")
    private String qrcode;

    /**
     * 签名
     */
    @TableField(value = "sign")
    @Excel(name = "签名")
    private String sign;

    /**
     * 角色组
     **/
    @TableField(exist = false)
    private List<SysRole> roles;

    @TableField(exist = false)
    private Long[] roleIds;

    @TableField(exist = false)
    private Long roleId;

    @TableField(exist = false)
    private String company;

    @TableField(exist = false)
    private String office;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @TableField(exist = false)
    private SysAdmininfo sysAdmininfo;

    @TableField(exist = false)
    private SysDoctorinfo sysDoctorinfo;

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public Long[] getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(Long[] roleIds) {
        this.roleIds = roleIds;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getOffice() {
        return office;
    }

    public void setOffice(String office) {
        this.office = office;
    }

    public SysAdmininfo getSysAdmininfo() {
        return sysAdmininfo;
    }

    public void setSysAdmininfo(SysAdmininfo sysAdmininfo) {
        this.sysAdmininfo = sysAdmininfo;
    }

    public SysDoctorinfo getSysDoctorinfo() {
        return sysDoctorinfo;
    }

    public void setSysDoctorinfo(SysDoctorinfo sysDoctorinfo) {
        this.sysDoctorinfo = sysDoctorinfo;
    }

    /**
     * 编号
     */
    public Integer getId() {
        return id;
    }

    /**
     * 编号
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * 归属公司
     */
    public String getCompany_id() {
        return company_id;
    }

    /**
     * 归属公司
     */
    public void setCompany_id(String company_id) {
        this.company_id = company_id;
    }

    /**
     * 归属部门
     */
    public String getOffice_id() {
        return office_id;
    }

    /**
     * 归属部门
     */
    public void setOffice_id(String office_id) {
        this.office_id = office_id;
    }

    /**
     * 登录名
     */
    @Xss(message = "用户账号不能包含脚本字符")
    @NotBlank(message = "用户账号不能为空")
    @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
    public String getLogin_name() {
        return login_name;
    }

    /**
     * 登录名
     */
    public void setLogin_name(String login_name) {
        this.login_name = login_name;
    }

    /**
     * 密码
     */
    public String getPassword() {
        return password;
    }

    /**
     * 密码
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * 账号使用人，医生id或者管理员id
     */
    public String getUse_by() {
        return use_by;
    }

    /**
     * 账号使用人，医生id或者管理员id
     */
    public void setUse_by(String use_by) {
        this.use_by = use_by;
    }

    /**
     * 工号
     */
    public String getNo() {
        return no;
    }

    /**
     * 工号
     */
    public void setNo(String no) {
        this.no = no;
    }

    /**
     * 姓名
     */
    @Xss(message = "真实姓名不能包含脚本字符")
    @Size(min = 0, max = 30, message = "真实姓名长度不能超过30个字符")
    public String getName() {
        return name;
    }

    /**
     * 姓名
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 邮箱
     */
    public String getEmail() {
        return email;
    }

    /**
     * 邮箱
     */
    @Email(message = "邮箱格式不正确")
    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * 电话
     */
    public String getPhone() {
        return phone;
    }

    /**
     * 电话
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * 手机
     */
    @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
    public String getMobile() {
        return mobile;
    }

    /**
     * 手机
     */
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    /**
     * 职位
     */
    public String getJob_name() {
        return job_name;
    }

    /**
     * 职位
     */
    public void setJob_name(String job_name) {
        this.job_name = job_name;
    }

    /**
     * 职级
     */
    public String getJob_level() {
        return job_level;
    }

    /**
     * 职级
     */
    public void setJob_level(String job_level) {
        this.job_level = job_level;
    }

    /**
     * 用户类型
     */
    public String getUser_type() {
        return user_type;
    }

    /**
     * 用户类型
     */
    public void setUser_type(String user_type) {
        this.user_type = user_type;
    }

    /**
     * 用户头像
     */
    public String getPhoto() {
        return photo;
    }

    /**
     * 用户头像
     */
    public void setPhoto(String photo) {
        this.photo = photo;
    }

    /**
     * 最后登陆IP
     */
    public String getLogin_ip() {
        return login_ip;
    }

    /**
     * 最后登陆IP
     */
    public void setLogin_ip(String login_ip) {
        this.login_ip = login_ip;
    }

    /**
     * 最后登陆时间
     */
    public Date getLogin_date() {
        return login_date;
    }

    /**
     * 最后登陆时间
     */
    public void setLogin_date(Date login_date) {
        this.login_date = login_date;
    }

    /**
     * 是否可登录
     */
    public String getLogin_flag() {
        return login_flag;
    }

    /**
     * 是否可登录
     */
    public void setLogin_flag(String login_flag) {
        this.login_flag = login_flag;
    }

    /**
     * 
     */
    public String getToken() {
        return token;
    }

    /**
     * 
     */
    public void setToken(String token) {
        this.token = token;
    }


    /**
     * 删除标记
     */
    public String getDel_flag() {
        return del_flag;
    }

    /**
     * 删除标记
     */
    public void setDel_flag(String del_flag) {
        this.del_flag = del_flag;
    }

    /**
     * 企业帐套
     */
    public String getAccount_id() {
        return account_id;
    }

    /**
     * 企业帐套
     */
    public void setAccount_id(String account_id) {
        this.account_id = account_id;
    }

    /**
     * 
     */
    public String getQrcode() {
        return qrcode;
    }

    /**
     * 
     */
    public void setQrcode(String qrcode) {
        this.qrcode = qrcode;
    }

    /**
     * 签名
     */
    public String getSign() {
        return sign;
    }

    /**
     * 签名
     */
    public void setSign(String sign) {
        this.sign = sign;
    }

    public List<SysRole> getRoles() {
        return roles;
    }

    public void setRoles(List<SysRole> roles) {
        this.roles = roles;
    }

    @Override
    public String toString() {
        return "SysUser{" +
                "id=" + id +
                ", company_id='" + company_id + '\'' +
                ", office_id='" + office_id + '\'' +
                ", login_name='" + login_name + '\'' +
                ", password='" + password + '\'' +
                ", use_by='" + use_by + '\'' +
                ", no='" + no + '\'' +
                ", name='" + name + '\'' +
                ", email='" + email + '\'' +
                ", phone='" + phone + '\'' +
                ", mobile='" + mobile + '\'' +
                ", job_name='" + job_name + '\'' +
                ", job_level='" + job_level + '\'' +
                ", user_type='" + user_type + '\'' +
                ", photo='" + photo + '\'' +
                ", login_ip='" + login_ip + '\'' +
                ", login_date=" + login_date +
                ", login_flag='" + login_flag + '\'' +
                ", token='" + token + '\'' +
                ", del_flag='" + del_flag + '\'' +
                ", account_id='" + account_id + '\'' +
                ", qrcode='" + qrcode + '\'' +
                ", sign='" + sign + '\'' +
                ", roles=" + roles +
                ", roleIds=" + Arrays.toString(roleIds) +
                ", roleId=" + roleId +
                ", company='" + company + '\'' +
                ", office='" + office + '\'' +
                ", sysAdmininfo=" + sysAdmininfo +
                ", sysDoctorinfo=" + sysDoctorinfo +
                '}';
    }

    public boolean isAdmin()
    {
        return isAdmin(this.getId().longValue());
    }

    public static boolean isAdmin(Long userId)
    {
        return userId != null && -1L == userId;
    }
}